package com.aigc.chinamobileai.ai.controller;

import org.springframework.ai.chat.memory.ChatMemoryRepository;
import org.springframework.ai.chat.messages.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.aigc.chinamobileai.ai.domin.vo.MessageVO;
import java.util.List;

@RestController
@RequestMapping("/ai/history")
public class ChatHistoryController {

    @Autowired
    private ChatMemoryRepository chatMemoryRepository;

    @GetMapping("{type}")
    public List<String> getChatId(@PathVariable String type){
        return chatMemoryRepository.findConversationIds();
    }

    @GetMapping("/{type}/{chatId}")
    public List<MessageVO> getMessage(@PathVariable String type,@PathVariable String chatId){
        List<Message> byConversationId = chatMemoryRepository.findByConversationId(chatId);
        return byConversationId.stream().map(MessageVO::new).toList();
    }
}
